package com.sansui.blog.service.impl;

import com.sansui.blog.dao.ArchiveDao;
import com.sansui.blog.dao.UserInfoDao;
import com.sansui.blog.pojo.Blog;
import com.sansui.blog.pojo.UserInfo;
import com.sansui.blog.service.ArchiveService;
import com.sansui.blog.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @name: ArchiveServiceImpl
 * @author: Sansui
 * @Software: IDEA
 * @Blog: https://www.cnblogs.com/sansui6/
 * @date: 2022-05-26 21:49
 **/
@Service
public class ArchiveServiceImpl implements ArchiveService {


    @Autowired
    private ArchiveDao archiveDao;

    @Override
    public Map<String, List<Blog>> getArchiveBlog() {
        List<String> years = archiveDao.getBlogYears();
        Map<String, List<Blog>> map = new TreeMap<String, List<Blog>>(
                new Comparator<String>() {
                    @Override
                    public int compare(String obj1, String obj2) {
                        // 降序排序
                        return obj2.compareTo(obj1);
                    }
                });

        for (String year : years){
            map.put(year,archiveDao.getBlogByYear(year));
        }

        return map;
    }

}
